<% add_decidim_meta_tags(
  title: translated_attribute(current_participatory_space.title),
  image_url: resolve_meta_image_url(current_participatory_space),
  description: translated_attribute(current_participatory_space.short_description),
  url: conference_url(current_participatory_space, locale: current_locale),
  resource: current_participatory_space) %>

<%
edit_link(
  resource_locator(current_participatory_space).edit,
  :update,
  :conference,
  conference: current_participatory_space
)
%>

<%= render partial: "layouts/decidim/header/follow_space_menu_bar_button", locals: { participatory_space: current_participatory_space } %>

<%# NOTE: This page is wrapped within a main tag, in order to
    include the hero inside the two-column layout.
    Therefore is mandatory to pass the "main_enabled: false" flag
    to the layout_two_col for disabling the original main. %>
<main>

  <%= content_for :aside do %>
    <div class="conference__nav-container">
      <button id="dropdown-trigger-conference" data-controller="dropdown" data-target="dropdown-menu-conference" data-auto-close="true" data-scroll-to-menu="true">
        <span><%= t("decidim.searches.filters.jump_to") %></span>
        <%= icon "arrow-down-s-line" %>
        <%= icon "arrow-up-s-line" %>
      </button>
      <ul id="dropdown-menu-conference" class="conference__nav" aria-hidden="true">
        <%= render partial: "layouts/decidim/conferences/conference_nav_item", collection: conference_nav_items(current_participatory_space), as: :item %>
      </ul>
    </div>
  <% end %>

  <%= render partial: "conference_hero" %>

  <% layout_style = conference_nav_items(current_participatory_space).any? ? "layout_two_col" : "layout_center" %>
  <%= render layout: "layouts/decidim/shared/#{layout_style}", locals: { reverse: true, main_enabled: false, columns: 10 } do %>

    <%= participatory_space_floating_help %>

    <section class="content-block">
      <h2 class="h2 decorator"><%= t("conferences.show.introduction", scope: "decidim") %></h2>
      <div class="content-block__description editor-content">
        <%= decidim_sanitize_editor_admin translated_attribute(current_participatory_space.short_description) %>
      </div>
    </section>

    <section class="content-block conference__content-block">
      <h2 class="h2 decorator"><%= t("conferences.show.details", scope: "decidim") %></h2>
      <div class="content-block__description editor-content">
        <%= decidim_sanitize_editor_admin translated_attribute(current_participatory_space.description) %>
      </div>

      <div>
        <% if current_participatory_space.registrations_enabled? %>
          <% if current_participatory_space.has_registration_for?(current_user) %>
            <%= link_to t("decidim.conferences.conferences.show.manage_registration"), decidim_conferences.conference_registration_types_path(current_participatory_space, locale: current_locale), class: "button button__lg button__primary" %>
          <% elsif current_participatory_space.has_published_registration_types? %>
            <%= link_to t("decidim.conferences.conferences.show.register"), decidim_conferences.conference_registration_types_path(current_participatory_space, locale: current_locale), class: "button button__lg button__secondary" %>
          <% end %>
        <% end %>
        <% current_participatory_space.components.where(manifest_name: "meetings").each do |component_meeting| %>
          <% if component_meeting.published? || component_meeting == self.try(:current_component) %>
            <%= link_to translated_attribute(component_meeting.name), decidim_conferences.conference_conference_program_path(current_participatory_space, id: component_meeting.id, locale: I18n.locale), class: "button button__lg button__transparent-secondary" %>
          <% end %>
        <% end %>
      </div>
    </section>

    <%= render partial: "partners", locals: { conference: current_participatory_space } %>

    <% unless translated_attribute(current_participatory_space.objectives).blank? %>
      <section class="content-block">
        <h2 class="h2 decorator"><%= t("decidim.conferences.show.objectives") %></h2>
        <div class="editor-content">
          <%= decidim_sanitize_editor_admin translated_attribute(current_participatory_space.objectives) %>
        </div>
      </section>
    <% end %>

    <%= render_hook(:conference_venues) %>

    <% if current_participatory_space.registrations_enabled? %>
      <section class="content-block">
        <% if current_participatory_space.has_published_registration_types? %>
          <h2 class="h2 decorator"><%= t("decidim.conferences.conferences.show.register") %></h2>
        <% end %>
        <% if current_user.present? %>
          <div class="conference__box">
            <div>
              <%= icon "user-follow-line", class: "conference__box-icon" %>
              <p class="conference__box-title"><%= t("decidim.conferences.conferences.show.make_conference_registration") %></p>
              <p class="conference__box-description"><%= t("decidim.conferences.conferences.show.login_as", name: current_user.name, email: current_user.email ) %></p>
            </div>
            <div>
              <% if current_participatory_space.has_registration_for?(current_user) %>
                <%= link_to t("decidim.conferences.conferences.show.manage_registration"), decidim_conferences.conference_registration_types_path(current_participatory_space, locale: current_locale), class: "button button__lg button__primary" %>
              <% elsif current_participatory_space.has_published_registration_types? %>
                <%= link_to t("decidim.conferences.conferences.show.register"), decidim_conferences.conference_registration_types_path(current_participatory_space, locale: current_locale), class: "button button__lg button__secondary" %>
              <% end %>
            </div>
          </div>
        <% else %>
          <%= render partial: "decidim/devise/shared/login_boxes", locals: { scope: "decidim.conferences.conferences.show" } %>
        <% end %>
      </section>
    <% end %>

    <%= cell("decidim/conferences/linked_participatory_spaces", current_participatory_space) %>

    <% if current_participatory_space.show_statistics? %>
      <section class="content-block" data-statistics>
        <h2 class="h2 decorator"><%= t("decidim.statistics.headline") %></h2>
        <%= cell("decidim/statistics", stats.collection) %>
      </section>
    <% end %>

  <% end %>
</main>
